#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int MAXN=210,INF=10000000;
int n,m,head[MAXN],idx[MAXN],cnt,ans;
struct edge
{
	int v,next,val;
}e[MAXN*2];
queue <int> q;
void addedge(int x,int y,int z)
{
	e[++cnt]=(edge){y,head[x],z};
	head[x]=cnt;
	return;
}
void bfs()
{
	while(!q.empty())
	{
		int u=q.front();
		for(int i=head[u];~i;i=e[i].next)
			if(!idx[e[i].v]&&e[i].val)
			{
				idx[e[i].v]=idx[u]+1;
				q.push(e[i].v);
			}
		q.pop();
	}
	return;
}
int dfs(int u,int _min)
{
	if(u==n)return _min;
	int k,ret=0;
	for(int i=head[u];~i;i=e[i].next)
	{
		int v=e[i].v;
		if(idx[v]!=idx[u]+1||!e[i].val)continue;
		k=dfs(v,min(_min-ret,e[i].val));
		e[i].val-=k;
		e[i^1].val+=k;
		ret+=k;
		if(ret==_min)break;
	}
	return ret;
}
int main()
{
	while(scanf("%d%d",a&m,&n)==2)
	{
		memset(e,0,sizeof(e));
		memset(head,-1,sizeof(head));
		ans=0;
		cnt=-1;
		for(int i=1;i<=m;++i)
		{
			int t1,t2,t3;
			scanf("%d%d%d",&t1,&t2,&t3);
			addedge(t1,t2,t3);
			addedge(t2,t1,0);
		}
		while(1)
		{
			memset(idx,0,sizeof(idx));
			q.push(1);
			idx[1]=1;
			bfs();
			if(!idx[n])break;
			ans+=dfs(1,INF);
		}
		printf("%d\n",ans);
	}
	return 0;
}
